package thread.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class PreLoader {

    private final FutureTask<ProductInfo> future = new FutureTask<ProductInfo>(new Callable<ProductInfo>() {
        @Override
        public ProductInfo call() throws Exception {
            return loadProductInfo();
        }
    });

    private final Thread thread = new Thread(future);

    public void start(){

        thread.start();
    }

    public ProductInfo get() throws  InterruptedException {

        try {
            return future.get();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
           return null;
    }

    public ProductInfo loadProductInfo(){

        //从数据库中加载数据
        return null;
    }
}
